#!/bin/bash
#系统初始化

#关闭selinux

sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
   echo "已关闭selinux，请重启系统并生效"

#关闭防火墙

systemctl disable firewalld
  echo "防火墙以关闭"

#配置ip

read -p "请输入要更改的IP：" ip
read -p "请输入要更改的网关：" gateway

cat <<EOF > /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE="Ethernet"
BOOTPROTO=none
IPADDR=$ip
PREFIX=24
GATEWAY=$gateway
DNS1=114.114.114.114
DNS2=223.5.5.5
NAME="ens33"
DEVICE="ens33"
ONBOOT="yes"
EOF

nmcli connection reload
nmcli connection up ens33

 echo "IP已配置为$ip"

#配置yum源

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo &> /dev/null

 echo "已配置阿里yum源"

#时间同步

yum install -y ntpdate
ntpdate time.windows.com

  echo "已同步时间"

#修改SSH默认端口

read -p "要修改的SSH端口为：" ssh
sed -i "s/#Port 22/Port $ssh/" /etc/ssh/sshd_config
systemctl restart sshd
  echo "SSH端口号已更改"



echo "系统初始化已完成"

